# -*- coding:utf-8 -*-
# @Time: 2020/8/31 13:46
# @Author: liupengfei
# @File: serializers.py

from rest_framework import serializers

from utils.serializersfield import ImageUploadCharField
from .models import AdornService, OrderService


class OrderServiceSerializers(serializers.ModelSerializer):
    service_name = serializers.CharField(source='adornService.name', read_only=True)

    class Meta:
        model = OrderService
        fields = ('id', 'name', 'service_name', 'mobile', 'address')


class AdornServiceSerializers(serializers.ModelSerializer):
    image_path = serializers.SerializerMethodField()
    image_arr = ImageUploadCharField(source='image', read_only=True)

    def get_image_path(self, obj):
        return obj.image.get_url() if obj.image else ''

    class Meta:
        model = AdornService
        fields = '__all__'
